home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / mini / Dial-On-Demand < prev    next >
Text File  |  1997-05-25  |  15KB  |  574 lines

  1. Dial-On-Demand mini-HOWTO
  2. Rodney.van.den.Oever@tip.nl
  3. Version 1.0, 28 July 1996 / updated and submitted 29 february 1997
  4.  
  5.  
  6. Introduction:
  7.  
  8. This document describes how to do dial-on-demand dialling and how to use a
  9. Linux host connected to a private local network as a dial-on-demand
  10. PPP-router.
  11.  
  12. The kerneld-mini-HOWTO already describes how kerneld can execute a
  13. 'request-route' script, I'd like to describe a working setup in more detail.
  14.  
  15. If you have a small network at home, this is a very elegant way to provide
  16. transparent Internet-access for a couple of other machines.
  17.  
  18.  
  19. ______________________________
  20. __|__                  ___|___
  21. |     | local network  |       |   ______  PPP-link to provider
  22. | PC  |  192.168.1.0   | Linux |--|modem |------------------>
  23. |     |                | Router|  |______|      x.x.x.x
  24. |_____|                |_______|          (dynamic IP-address)
  25.                          named
  26.                          pppd
  27.  
  28. This setup requires:
  29.  
  30. * Kernel 2.0.0 or later.
  31. * ppp-2.2.0f.tar.gz or later
  32. * modules-2.0.0.tar.gz or later
  33. * ipfwadm-2.3.tar.gz (http://www.xos.nl/linux/ipfwadm)
  34.  
  35.  
  36. The following steps need to be taken:
  37.  
  38. 1. Kernel Configuration
  39. 2. Modules Installation
  40. 3. PPP Installation
  41. 4. Serial Port and Modem Configuration
  42. 5. PPP Configuration
  43. 6. Dial-On-Demand
  44. 7. Network Configuration
  45. 8. Masquerading configuration
  46. 9. Workstation configuration
  47.  
  48. ----------------------------------------------------------------------------
  49.  
  50. ---
  51.  
  52.  
  53. 1. Kernel Configuration:
  54.  
  55. First we need to compile a kernel with kerneld, ppp and IP-masquerading
  56. support.
  57. I'll only show the options required for this setup, other options like
  58. firewall
  59. logging or transparent proxying can be turned on, but are not required:
  60.  
  61. cd /usr/src/linux
  62. make config (or make menuconfig)
  63.  
  64. * Code maturity level options
  65. *
  66. Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL)
  67.  
  68. [Y/n/?]
  69.  
  70. * Loadable module support
  71. *
  72. Enable loadable module support (CONFIG_MODULES) [Y/n/?]
  73. Set version information on all symbols for modules (CONFIG_MODVERSIONS)
  74. [N/y/?]
  75. Kernel daemon support (e.g. autoload of modules) (CONFIG_KERNELD) [Y/n/?]
  76. *
  77. Networking support (CONFIG_NET) [Y/n/?]
  78. *
  79. * Networking options
  80. *
  81. Network firewalls (CONFIG_FIREWALL) [Y/n/?]
  82. TCP/IP networking (CONFIG_INET) [Y/n/?]
  83. IP: forwarding/gatewaying (CONFIG_IP_FORWARD) [Y/n/?]
  84. IP: firewalling (CONFIG_IP_FIREWALL) [Y/n/?]
  85. IP: masquerading (EXPERIMENTAL) (CONFIG_IP_MASQUERADE) [Y/n/?]
  86. *
  87. * Protocol-specific masquerading support will be built as modules.
  88. *
  89. IP: always defragment (CONFIG_IP_ALWAYS_DEFRAG) [Y/n/?]
  90. IP: optimize as router not host (CONFIG_IP_ROUTER) [Y/n/?]
  91. *
  92. * Network device support
  93. *
  94. Network device support (CONFIG_NETDEVICES) [Y/n/?]
  95. *
  96. PPP (point-to-point) support (CONFIG_PPP) [M/n/y/?]
  97. *
  98. * CCP compressors for PPP are only built as modules.
  99. *
  100. Ethernet (10 or 100Mbit) (CONFIG_NET_ETHERNET) [Y/n/?]
  101. NE2000/NE1000 support (CONFIG_NE2000) [Y/m/n/?]
  102.  
  103.  
  104. The latter option depends of course on the netword card used!
  105.  
  106.  
  107. Compile the kernel with:
  108.  
  109. make zlilo
  110. make modules
  111. make modules_install
  112.  
  113. If you don't use LILO, copy /usr/src/linux/arch/i386/boot/zImage to the
  114. proper
  115. location for your setup.
  116. The modules are installed in /lib/modules/x.x.x, Where x.x.x reflects the
  117. version-number of your kernel.
  118.  
  119. ----------------------------------------------------------------------------
  120.  
  121. ---
  122.  
  123.  
  124. 2. Modules Installation:
  125.  
  126. The following module-utilities are required:
  127.  
  128. /sbin/insmode           Loads module requested
  129. /sbin/rmmod             Removes module no longer needed
  130. /sbin/depmod            Creates depedencies
  131. /sbin/kerneld           Kerneld extension to load modules automatically
  132.  
  133. If you don't have these yet, install 'm by:
  134.  
  135. cd /usr/src
  136. tar zxf modules-2.0.0.tar.gz
  137. make install
  138.  
  139. To load kerneld at startup we need to edit /etc/rc.d/rc.S or create a
  140. seperate
  141. script rc.modules which is called from rc.S. Add or change the following
  142. lines:
  143.  
  144. /etc/rc.d/rc.modules:
  145.  
  146. if [ ! -f /lib/modules/`uname -r`/modules.dep ] ; then
  147.         echo "Updating module dependencies for Linux `uname -r`:"
  148.         /sbin/depmod -a
  149. fi
  150.  
  151. [ -x /sbin/kerneld ] && /sbin/kerneld
  152.  
  153.  
  154. The first part checks for the module-dependencies and creates them if they
  155. don't
  156. exist yet.
  157.  
  158. ----------------------------------------------------------------------------
  159.  
  160. ---
  161.  
  162.  
  163. 3. PPP Installation:
  164.  
  165. The following stuff is required to setup a PPP-link:
  166.  
  167. /usr/sbin/pppd            PPP-daemon
  168. /usr/sbin/pppstats        PPP-statistics
  169. /usr/sbin/chat            Execution of scripts
  170.  
  171. Install these by:
  172.  
  173. cd /usr/src
  174. tar zxf ppp-2.2.0f.tar.gz
  175. cd ppp-2.2.0f
  176. ./configure
  177. make kernel
  178.  
  179. Since later kernels already include the PPP-code, 'make kernel' won't
  180. replace
  181. anything. Check the README and Makefile for shadow-support (if you also
  182. want to
  183. dial-in to this host) and other options. Then do:
  184.  
  185. make
  186. make install
  187.  
  188. ----------------------------------------------------------------------------
  189.  
  190. ---
  191.  
  192.  
  193. 4. Serial port and modem configuration:
  194.  
  195. This setup requires a modem. Serial port setup is done in /etc/rc.d/rc.seria
  196.  
  197. l:
  198.  
  199. ${SETSERIAL} /dev/cua0 uart 16450 port 0x3F8 irq 4
  200. ${SETSERIAL} /dev/cua1 uart 16550A port 0x2F8 irq 3 spd_vhi
  201.  
  202. In this setup COM1 is used by the mouse and COM2 by an internal 28k8
  203. modem.
  204. The spd_vhi-parameter replace the 38400 bps-entry in the speeds-table with
  205. 115200.
  206. Likewise, spd_hi replaces this by 57600.
  207.  
  208. Use spd_vhi with a 28k8 modem and spd_hi with a 14k4 modem, but start with
  209. 38400,
  210. just to be on the safe side.
  211.  
  212. You can check your modem setup by running 'minicom' or some other terminal
  213. program.
  214. Your modem should echo the characters typed. Use Ctrl-A, P to change the
  215. communication parameters. Check if it still works at 57600 or 115200 bps.
  216. Entering 'ATZ' should return 'OK'. Use Ctrl-A X to leave minicom.
  217.  
  218. Minicom can also be used to dial your provider manually. Make a note of
  219. what you
  220. need to enter to setup the link and what the response are from the remote
  221. server.
  222. If your provider doesn't use PAP or CHAP you probably need to enter a
  223. username and
  224. password and possibly enter a command to setup the link in PPP-mode.
  225.  
  226. ----------------------------------------------------------------------------
  227.  
  228. ---
  229.  
  230.  
  231. 5. PPP Configuration:
  232.  
  233. pppd searches /etc/ppp for scripts and the file 'options'.
  234.  
  235. /etc/ppp/options:
  236.  
  237. /dev/modem 38400 crtscts modem noipdefault defaultroute idle-disconnect
  238. 120
  239.  
  240. Meaning:
  241.  
  242. /dev/modem      In my setup a link to /dev/cua1.
  243. 38400           Gets replaced by 115200 (spd_vhi-parameter in
  244. /etc/rc.d/rc.serial)
  245. crtscts         Hardware handshake, RTS/CTS, don't use Xon-Xoff-handshaking!
  246.  
  247.  
  248. noipdefault     The IP-address is assigned automatically.
  249. defaultroute    This sets the default route to the PPP-interface when the
  250. link is up.
  251. idle-disconnect PPP-2.2.0f automatically disconnects an idle link after
  252. 120
  253. seconds.
  254.  
  255. Now we need to create a script, just name it 'default', meaning the ISP
  256. you
  257. normally
  258. use. If you want to make other connections too, creates differents scripts
  259. for these
  260. sites and name them with the remote IP-address.
  261.  
  262. /etc/ppp/default:
  263.  
  264. "" ats11=55dtXXXXXXXX CONNECT "" rname: UUUUU sword: PPPPP > ppp
  265.  
  266.  
  267. Meaning:
  268.  
  269. ats11=55        shortens the duration of the dial tones to speed up
  270. dialing.
  271. XXXXXXXX        Enter the phone-number for your provider here.
  272. CONNECT         chat waits for your modem to return 'CONNECT'.
  273. rname:          chat waits for 'rname', and enters 'UUUUU'
  274. sword:          chat waits for 'sword', and then enters 'PPPPP'.
  275.  
  276. Replace 'UUUUU' and 'PPPPP' by your username and password. I use 'rname'
  277. and
  278. 'sword' because sometimes the first letter gets missed or could be upper-
  279. or
  280. lowercase and language-dependent. Some ISP's require you to enter 'ppp'
  281. after
  282. your enter the username and password, so I wait for the last character of
  283. the
  284. routerprompt ('>').
  285.  
  286. If you get errors like 'serial line looped back' or 'serial line not 8-bit
  287. clean'
  288. the link is not yet in PPP-mode.
  289.  
  290. This command is long enough to place it in a small script:
  291.  
  292. /etc/ppp/ppp:
  293.  
  294. #!/bin/sh
  295. /usr/sbin/pppd connect '/usr/sbin/chat -v -f /etc/ppp/default'
  296.  
  297. You should now be able to connect to your ISP, you might add the 'debug'
  298. parameter
  299. to the /etc/ppp/options-file, make sure you increase the loglevel of
  300. syslogd to
  301. see whats going on:
  302.  
  303. /etc/syslog.conf
  304. *.debug                                 /var/log/messages
  305.  
  306. If you edit syslog.conf be sure to notify syslogd about this change.
  307. Depending on
  308. the location of its PID-file, do:
  309.  
  310. kill -1 `cat /var/run/syslog.pid`
  311.  
  312. or
  313.  
  314. kill -1 `cat /etc/syslog.pid`
  315.  
  316.  
  317. After the connection is made, check with 'ifconfig' for the existing of a
  318. 'ppp0'-
  319. interface. Check your default route with 'netstat -r', it should point to
  320. your ISP.
  321. Try pinging a remote server, e.g. your providers nameserver.
  322.  
  323. If this works you could add this nameserver to your /etc/resolv.conf:
  324.  
  325. search your.isp.domain
  326. nameserver x.x.x.x
  327.  
  328. ----------------------------------------------------------------------------
  329.  
  330. ---
  331.  
  332.  
  333. 6. Dial-on-Demand:
  334.  
  335. Kerneld can be used to load modules, like ppp, on demand. An additional
  336. feature,
  337. described in the kerneld-HOWTO, is the ability to invoke a script, if a
  338. particular
  339. route is missing. Kerneld will look for '/sbin/request-route'. The script
  340. below is
  341. an almost exact copy of the script included with the modules-2.0.0.tar.gz:
  342.  
  343. /sbin/request-route:
  344.  
  345. #!/bin/sh
  346. LOCK=/var/run/request-route.pid
  347. export PATH=/usr/sbin:$PATH     # for ppp-2.2*
  348.  
  349. # This script will be called from kerneld with the requested route as $1
  350.  
  351. chatfile=/etc/ppp/$1
  352.  
  353. # If no chatscript exists use a default value (symlink to preferred
  354. script):
  355.  
  356. [ ! -f $chatfile ] && chatfile=/etc/ppp/default
  357.  
  358. # Check if we're already running:
  359.  
  360. if [ ! -f $LOCK ] ; then
  361.         pppd connect "chat -f $chatfile" &
  362.  
  363.         # Timer to be killed by ip-up, tunable! Check kerneld delay as
  364. well
  365.         sleep 60 &
  366.         sleepid=$!
  367.         echo $sleepid > $LOCK
  368.         wait $sleepid
  369.         rm -f $LOCK
  370.         exit 0
  371. fi
  372. exit 1
  373.  
  374.  
  375. Kerneld will run this script using the missing route as an argument:
  376.  
  377. /sbin/request-route x.x.x.x
  378.  
  379. The script uses a lock-file to prevent multiple 'request-route'-instances.
  380.  
  381. At first I used a script that was triggered by a nameserver query, but
  382. since I like
  383. to run a local nameserver, this lookup would be cached and a second query
  384. wouldn't
  385. bring the link up. That's why I changed the script to use a default
  386. chat-script if
  387. none exists.
  388.  
  389. This also allows you to create multiple chat-scripts for different links
  390. and use a
  391. default chat-script to connect to your ISP.
  392.  
  393. After the link has been brought up, pppd executes the script /etc/ppp/ip-up
  394.  
  395. which
  396. removes the lock-file. Add commands you'd like to execute everytime the
  397. link is
  398. brought up, like a sendmail queue-run:
  399.  
  400. #!/bin/ash
  401. LOCK=/var/run/request-route.pid
  402. [ -f $LOCK ] && kill `cat $LOCK`
  403.  
  404. # Execute these commands after connecting:
  405. #/usr/sbin/sendmail -q
  406.  
  407.  
  408. The 'idle-disconnect'-option automatically disconnects an idle link, use
  409. 'ppp-off'
  410. is you want to disconnect immediately:
  411.  
  412. /usr/sbin/ppp-off:.
  413.  
  414. #!/bin/sh
  415. LOCK=/var/run/request-route.pid
  416. DEVICE=ppp0
  417.  
  418. rm -f $LOCK
  419. #
  420. # If the ppp0 pid file is present then the program is running. Stop it.
  421. if [ -r /var/run/$DEVICE.pid ]; then
  422.         kill -INT `cat /var/run/$DEVICE.pid`
  423. #
  424. # If unsuccessful, ensure that the pid file is removed.
  425. #
  426.         if [ ! "$?" = "0" ]; then
  427.                 echo "removing stale $DEVICE pid file."
  428.                 rm -f /var/run/$DEVICE.pid
  429.                 exit 1
  430.         fi
  431. #
  432. # Success. Terminate with proper status.
  433. #
  434.         echo "$DEVICE link terminated"
  435.         exit 0
  436. fi
  437. #
  438. # The link is not active
  439. #
  440. echo "$DEVICE link is not active"
  441.  
  442. exit 1
  443.  
  444. ----------------------------------------------------------------------------
  445.  
  446. ---
  447.  
  448.  
  449. 7. Network Configuration:
  450.  
  451. If your Linux-box has another network interface, like an Ethernet-card or
  452. if you
  453. use PLIP to connect to another machine, you can configure this box to
  454. function as
  455. a router. This is how I configured my network, I always enter all
  456. IP-addresses in
  457. /etc/hosts so I only have one file to maintain:
  458.  
  459. /etc/hosts:
  460.  
  461. 127.0.0.1       localhost
  462. 10.0.0.1        your.domain.com host
  463. 10.0.0.2        some.other.machine
  464.  
  465.  
  466. /etc/networks:
  467.  
  468. loopback        127.0.0.0
  469. localnet        10.0.0.0
  470.  
  471.  
  472. /etc/rc.d/inet1:
  473.  
  474. # Loopback interface:
  475. ifconfig lo localhost
  476. route add -net loopback
  477.  
  478. # Local interface:
  479. ifconfig eth0 host
  480. route add -net localnet eth0
  481.  
  482.  
  483. The last rule adds a route to the local network. We don't need to enter
  484. the
  485. default
  486. gateway here, since we don't have one until a PPP-link is setup.
  487.  
  488. ----------------------------------------------------------------------------
  489.  
  490. ---
  491.  
  492.  
  493. 8. Masquerading Configuration:
  494.  
  495. If you need to connect multiple machines, but only have one IP-address,
  496. you
  497. can use
  498. the Linux masquerading feature. This allows you to configure an internal
  499. network-
  500. number (preferably a private IP-address) which gets translated to the
  501. IP-address
  502. assigned to the PPP-interface.
  503.  
  504. You are free to use the following network numbers:
  505.  
  506. Class A: 10.0.0.0
  507. Class B: 172.16.0.0 - 172.31.0.0
  508. Class C: 192.168.0.0 - 192.168.254.0
  509.  
  510.  
  511. Add the following rules to /etc/rc.d/rc.inet1:
  512.  
  513. FW=/sbin/ipfwadm
  514.  
  515. ${FW} -F -f
  516.  
  517. ${FW} -F -a m -P tcp -S localnet/8 -D default/0
  518. ${FW} -F -a m -P udp -S localnet/8 -D default/0
  519.  
  520. # Masquerading timeout-values (tcp tcpfin udp), defaults:
  521. ${FW} -M -s 3600 0 0
  522.  
  523. # Load module for special protocols:
  524. /sbin/modprobe ip_masq_ftp
  525. /sbin/modprobe ip_masq_raudio
  526. /sbin/modprobe ip_masq_irc
  527.  
  528.  
  529. The two masquerading rules will translate UDP and TCP-traffic to the
  530. IP-address
  531. used as the default gateway (the PPP-interface). Ping, which uses the
  532. ICMP-protocol,
  533. will fail from other hosts, it will only work from the router.
  534. I used network 10.0.0.0 with subnet mask 255.0.0.0 or in CIDR-notation:
  535. '/8'.
  536.  
  537. The next rule prevents FTP-DATA connections from timing out, by increasing
  538. the TCP-
  539. timeout value.
  540.  
  541. The modules are only required if you want to use these protocols across
  542. the
  543. firewall.
  544. E.g. if you want to use normal ftp through the firewall, you need to load
  545. the
  546. ip_masq_ftp-module.
  547.  
  548. ----------------------------------------------------------------------------
  549.  
  550. ----
  551.  
  552. 9. Workstation Configuration:
  553.  
  554. Configure your other machine for your local network number and set them up
  555. to
  556. use the Linux-box as their default gateway.
  557.  
  558. ----------------------------------------------------------------------------
  559.  
  560. ----
  561.  
  562. 10. Disclaimer
  563.  
  564. This document describes a configuration that works for me, use it at your
  565. own
  566. risk. If anything substantial is missing or if something is terribly
  567. wrong,
  568. please let me know!
  569.  
  570. One thing I could add is a description of how to setup a local nameserver.
  571.  
  572.  
  573. Rodney van den Oever <Rodney.van.den.Oever@tip.nl>
  574.